﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Susam
{

    // Full relator list can be found at http://www.loc.gov/marc/relators/relacode.html
    public static class SusamExtensions
    {
        internal static Relator ToRelator(this System.Xml.Linq.XElement element)
        {
            XNamespace xNamespace = element.Attribute("xmlns") != null ? element.Attribute("xmlns").Value : XNamespace.None;

            var relator = new Relator();
            relator.role = (String)element.Attributes().FirstOrDefault(e => e.Name.LocalName == "role");

            String fileas = (String)element.Attributes().FirstOrDefault(e => e.Name.LocalName == "file-as");
            if (fileas == null)
            {
                fileas = element.Value;
            }
            relator.name = fileas;

            return relator;
        }

    }

}
